package com.itheima.test1;

import java.util.Comparator;
import java.util.Random;
import java.util.Set;
import java.util.TreeSet;

public class Test {
    public static void main(String[] args) {
        Set<Teacher> ts = new TreeSet<>(new Comparator<Teacher>() {
            @Override
            public int compare(Teacher o1, Teacher o2) {
                //工号的升序
                int id1 = Integer.parseInt(o1.getTid());
                int id2 = Integer.parseInt(o2.getTid());
                int result =id1-id2;
                //姓名的降序
                result = result == 0 ? o2.getName().compareTo(o1.getName()) : result;
                return result;
            }
        });
        Teacher t1 = getTeacher("张三");
        Teacher t2 = getTeacher("李四");
        ts.add(t1);
        ts.add(t2);
        System.out.println(ts);
    }

    public static Teacher getTeacher(String name) {
        Random r = new Random();
        int tid = r.nextInt(5);
        Teacher t = new Teacher("" + tid, name);

//        Student集合
        TreeSet<Student> ss = new TreeSet<>(new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                //学号的降序
                int id1 = Integer.parseInt(o1.getSid());
                int id2 = Integer.parseInt(o2.getSid());
                int result =id2-id1;
                //姓名的升序
                result = result == 0 ? o1.getName().compareTo(o2.getName()) : result;
                return result;
            }
        });
//        添加5个Student类
        for (int i = 0; i < 5; i++) {
            int sid = r.nextInt(20);
            String sName = "";
            for (int j = 0; j < 2; j++) {
                int n = r.nextInt('z' - 'a') + 'a';
                sName += (char) n;
            }
            Student s = new Student("" + sid, "" + sName);
            ss.add(s);
        }

        t.setTsStudent(ss);
        return t;
    }
}
